package com.grm.workflow.controller;

import com.grm.common.annotation.Log;
import com.grm.common.entity.PageResult;
import com.grm.common.entity.Result;
import com.grm.workflow.request.model.WfModelAddParam;
import com.grm.workflow.request.model.WfModelDesignParam;
import com.grm.workflow.request.model.WfModelQueryParam;
import com.grm.workflow.request.model.WfModelUpdateParam;
import com.grm.workflow.response.WfModelResponse;
import com.grm.workflow.service.WfModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/workflow/model")
public class WfModelController {
    @Autowired
    private WfModelService wfModelService;

    @PostMapping("/list")
    public Result querySelective(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestBody WfModelQueryParam queryParam) {
        // 开启分页
        PageResult<WfModelResponse> pageResult = wfModelService.querySelective(pageNum,pageSize,queryParam);
        return Result.success(pageResult.getData(),pageResult.getTotal());
    }

    /**
     * 添加模型，此时还没有进行流程设计，没有xml
     */
    @PostMapping("/add")
    public Result add(@RequestBody WfModelAddParam addParam) {
        wfModelService.add(addParam);
        return Result.success();
    }

    /**
     * 修改模型，只修改分类和备注(流程实例的分类在部署时修改，不在此处修改)
     */
    @PutMapping("/update")
    public Result update(@RequestBody WfModelUpdateParam updateParam) {
        wfModelService.update(updateParam);
        return Result.success();
    }

    /**
     * 模型设计(xml、form表单)
     */
    @PostMapping("/design")
    public Result design(@RequestBody WfModelDesignParam designParam) {
        wfModelService.design(designParam);
        return Result.success();
    }

    /**
     * 删除模型
     */
    @DeleteMapping("/delete/{modelId}")
    public Result delete(@PathVariable String modelId) {
        wfModelService.delete(modelId);
        return Result.success();
    }

    /**
     * 部署流程模型
     */
    @PostMapping("/deploy/{modelId}")
    public Result deploy(@PathVariable String modelId) {
        wfModelService.deploy(modelId);
        return Result.success();
    }

    /**
     * 模型流程图Image
     */
    @GetMapping("/bpmn/image/{modelId}")
    public Result queryBpmnImage(@PathVariable String modelId) {
        String image = wfModelService.queryBpmnImage(modelId);
        return Result.success(image);
    }

    /**
     * 模型流程图xml
     */
    @GetMapping("/bpmn/xml/{modelId}")
    public Result queryBpmnXml(@PathVariable String modelId) {
        String xml = wfModelService.queryBpmnXml(modelId);
        return Result.success(xml);
    }
}
